/*
 * @lc app=leetcode.cn id=290 lang=javascript
 *
 * [290] 单词规律
 */

// @lc code=start
/**
 * @param {string} pattern
 * @param {string} s
 * @return {boolean}
 */
var wordPattern = function(pattern, s) {
    let ruleMap = new Map()
    s = s.split(' ')
    if (s.length !== pattern.length) {
        return false
    }
    if (new Set(pattern).size !== new Set(s).size) {
        return false
    }
    let flag = true
    for (let index = 0; index < pattern.length; index++) {
        const element = pattern[index]
        const sItem = s[index]
        if (!ruleMap.get(element)) {
            ruleMap.set(element, sItem)
        }
        if (ruleMap.get(element) !== sItem) {
            flag = false
        }
    }
    return flag
};
// @lc code=end

